Conversation
yurii-zadryhun
approved these changes
Nov 4, 2025
Co-authored-by: Yurii Zadryhun <dev.yuri.z@gmail.com>
Co-authored-by: Yurii Zadryhun <dev.yuri.z@gmail.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for an insertOrSkip() method that enables idempotent inserts by skipping rows that would cause duplicate key conflicts. The implementation uses database-specific syntax (INSERT IGNORE for MySQL, ON CONFLICT DO NOTHING for PostgreSQL, INSERT OR IGNORE for SQLite) while throwing an exception for SQL Server where this feature is not natively supported.
Key changes:
- Added
InsertModeenum withINSERTandIGNOREcases to control insert behavior - Implemented
insertOrSkip()method inTable,SeedInterface, andBaseSeedclasses - Modified adapter interfaces and implementations to support the new insert mode parameter
- Added comprehensive test coverage for all database adapters
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Db/InsertMode.php | New enum defining insert modes (standard INSERT vs INSERT IGNORE) |
| src/Db/Table.php | Added insertOrSkip() method and insert mode property to support skip-on-duplicate behavior |
| src/SeedInterface.php | Added insertOrSkip() interface method for seeder classes |
| src/BaseSeed.php | Implemented insertOrSkip() method in base seeder class |
| src/Db/Adapter/AdapterInterface.php | Updated insert methods to accept optional InsertMode parameter |
| src/Db/Adapter/AbstractAdapter.php | Added getInsertPrefix() method to generate INSERT IGNORE syntax and updated insert methods |
| src/Db/Adapter/MysqlAdapter.php | Updated docblock type annotations for consistency |
| src/Db/Adapter/PostgresAdapter.php | Implemented PostgreSQL-specific ON CONFLICT DO NOTHING syntax via getConflictClause() |
| src/Db/Adapter/SqliteAdapter.php | Implemented SQLite-specific INSERT OR IGNORE syntax via getInsertPrefix() |
| src/Db/Adapter/SqlserverAdapter.php | Added exception throwing for unsupported INSERT IGNORE operation |
| src/Db/Adapter/AdapterWrapper.php | Updated wrapper methods to pass through InsertMode parameter |
| src/Db/Adapter/TimedOutputAdapter.php | Updated timed output methods to pass through InsertMode parameter |
| src/View/Helper/MigrationHelper.php | Enhanced docblock type annotation for better type safety |
| tests/TestCase/Db/Adapter/MysqlAdapterTest.php | Added three test cases covering duplicate handling, bulk inserts, and normal inserts |
| tests/TestCase/Db/Adapter/PostgresAdapterTest.php | Added three test cases covering duplicate handling, bulk inserts, and normal inserts |
| tests/TestCase/Db/Adapter/SqliteAdapterTest.php | Added three test cases covering duplicate handling, bulk inserts, and normal inserts |
| tests/TestCase/Db/Adapter/SqlserverAdapterTest.php | Added test case verifying exception is thrown for unsupported operation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
markstory
reviewed
Nov 8, 2025
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves cakephp/phinx#2205
Follows #939 and in general helps to implement safer idempotent seeding.
Database Support:
The current implementation also allows other modes internally in the future, including update (upsert)
Out of scope: insertOrUpdate()
INSERT ... ON DUPLICATE UPDATE - Complex
Database Support Matrix
We can still add insertOrUpdate() later if needed
Example future use: